# -*- coding: utf-8 -*-

APPLET  = fourtou-applet
SCRIPT  = fourtou.py
SERVICE = org.gnome.panel.applet.FourtouAppletFactory.service
FACTORY = org.gnome.applets.FourtouApplet.panel-applet
prefix     = /usr
bindir     = $(prefix)/libexec
servicedir = $(prefix)/share/dbus-1/services
datadir    = $(prefix)/share/gnome-applets/fourtou
appletdir  = $(prefix)/share/gnome-panel/applets
builddir   = ./build
INSTALL      = install -c
INSTALL_BIN  = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644


all: $(builddir)/$(APPLET)


$(builddir)/$(APPLET):
	@echo "INSTALL PREFIX:" $(prefix)
	-mkdir  $(builddir)
	cp -f  ./$(SCRIPT)  $(builddir)/
	cp -f  ./$(SERVICE)  $(builddir)/
	cp -f  ./$(FACTORY)  $(builddir)/
	sed -i  "s|DATADIR\ =\ \"./\"|DATADIR\ =\ \"$(datadir)/\"|g"  $(builddir)/$(SCRIPT)
	sed -i  "s|/usr/libexec|$(bindir)|g"  $(builddir)/$(SERVICE)
	sed -i  "s|/usr/libexec|$(bindir)|g"  $(builddir)/$(FACTORY)
	sed -i  "s|/usr/share/gnome-applets/fourtou|$(datadir)|g"  $(builddir)/$(FACTORY)
	mv -f  $(builddir)/$(SCRIPT)  $(builddir)/$(APPLET)
	@echo "***"
	@echo "Execute 'make install' (as root) to install the applet."


help:
	@echo "Usage:";
	@echo "make  { all | install | uninstall | help | clean }"


install:
	$(INSTALL_BIN)  $(builddir)/$(APPLET)  $(bindir)/
	$(INSTALL_DATA)  $(builddir)/$(SERVICE)  $(servicedir)/
	$(INSTALL_DATA)  $(builddir)/$(FACTORY)  $(appletdir)/
	mkdir -p  $(datadir)
	$(INSTALL_DATA)  ./fourtou.glade  $(datadir)/
	$(INSTALL_DATA)  ./fourtou.svg  $(datadir)/


uninstall:
	-rm -f  $(bindir)/$(APPLET)
	-rm -f  $(servicedir)/$(SERVICE)
	-rm -f  $(appletdir)/$(FACTORY)
	-rm -f  $(datadir)/fourtou.glade
	-rm -f  $(datadir)/fourtou.svg
	-rmdir  $(datadir)


clean:
	-rm -f  $(builddir)/*
	-rmdir  $(builddir)


.PHONY: help clean install uninstall


# END

